package inc.zhugastrov.sellerform;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class OrdersTableModel extends AbstractTableModel {
	private String[] columnNames = { "ID", "Date", "Seller", "Total Price"};;
	private Vector<OrderIntr> dataVector;

	public OrdersTableModel() {
		dataVector = new Vector<OrderIntr>();

	}

	public String getColumnName(int column) {
		return columnNames[column];
	}

	public Object getValueAt(int row, int column) {
		OrderIntr order = (OrderIntr) dataVector.get(row);
		switch (column) {
		case 0:
			return order.getId();
		case 1:
			return order.getDate();
		case 2:
			return order.getSellerId();
		case 3:
			return order.getTotalPrice();
		default:
			return null;
		}
	}

	public boolean isCellEditable(int row, int column) {
		return false;
	}
	
		
	public void changeAmount(int amount, Item item) {
		item.setAmountInStore(amount);
	}
	

	public OrderIntr findWithId(Long id) {
		for (OrderIntr order : dataVector) {
			if (order.getId() == id)
				return order;
		}
		return null;
	}

	public int getRowCount() {
		return dataVector.size();
	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public void addRow(OrderIntr order) {
		dataVector.add(order);
		fireTableRowsInserted(dataVector.size() - 1, dataVector.size() - 1);

	}

	public OrderIntr getRow(int selectedRow) {
		if (selectedRow <= getRowCount())
			return dataVector.get(selectedRow);
		return null;
	}
	
	public void deleteRow(int rowNumber){
		dataVector.remove(rowNumber);
	}
}
